package com.breezelin.freshmarket.entities.rsp;

/**
 * Created by Breeze Lin
 * 0:48 2016/5/19
 * 1linyufeng1@gmail.com
 */

import com.breezelin.freshmarket.entities.JsonStruct;
import com.breezelin.freshmarket.entities.data.Product;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 查询结果回应
 */
public class QueryRsp implements JsonStruct {

	/**
	 * 产品集合
	 */
	private List<Product> commodities;

	public List<Product> getCommodities() {
		return commodities;
	}

	@Override
	public void fromJson(JSONObject jsonObject) {
		commodities = new ArrayList<>();
		JSONArray commoditiesJson = jsonObject.optJSONArray("Commoditys");
		if (commoditiesJson != null) {
			for (int i = 0; i < commoditiesJson.length(); i++) {
				commodities.add(new Product(commoditiesJson.optJSONObject(i)));
			}
		}
	}

	@Override
	public JSONObject toJson() {
		return new JSONObject();
	}
}
